<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>门店列表</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  {include file="public/css"/}
</head>
<body>
  <div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-card layui-col-md12">
          <div class="layui-card-body" pad15>
						<div class="layui-col-md12">
							<table id="tabledata" lay-filter="tabledata"></table>
						</div>
          </div>
        </div>
    </div>
  </div>
	{include file="public/js"/}
	<script>
  var table = layui.table;
	var datawhere = {};
  //数据表
  var tableIns = table.render({
    elem: '#tabledata'
    ,url: "{:url('chooseindex')}" //数据接口
    ,page: true //开启分页
    ,cols: [[ //表头
			{type:"checkbox"},
          {field: 'id', title: 'ID','width':60},
          {field: 'name', title: '门店名称','width':160},
          {field: 'pic', title: '门店图片',templet:function(d){return '<img src="'+d.pic+'" style="width:100px;"/>';}},
          {field: 'address', title: '门店电话/地址',templet:function(d){return '<div>'+d.tel+'</div><div>'+d.address+'</div>';}},
          {field: 'sort', title: '创建时间',templet:function(d){ return date('Y-m-d H:i',d.createtime)}},
		  {field: 'status', title: '状态',templet:function(d){ 
			if(d.status==0){
				return '<span style="color:red">已关闭</span>';
			}else if(d.status==1){
				return '<span style="color:green">已开启</span>';
			}
	      }},
		  {field: 'operation', title: '操作',templet: '<div><button class="table-btn" onclick="choosemendian(\'{{d.id}}\')">选择</button></div>',align:'center'}
    ]]
  });
	function choosemendian(id){
		var index = layer.load();
		$.post("{:url('choosemendian')}",{id:id},function(res){
			layer.close(index);
            window.parent.choosemendian(res.data,"{$Request.param.args}");
			var index = parent.layer.getFrameIndex(window.name);
			parent.layer.close(index);
		})
	}
	//排序
	table.on('sort(tabledata)', function(obj){
		datawhere.field = obj.field;
		datawhere.order = obj.type;
		tableIns.reload({
			initSort: obj,
			where: datawhere
		});
	});
	//检索
	layui.form.on('submit(LAY-app-forumreply-search)', function(obj){
		var field = obj.field
		var olddatawhere = datawhere
		datawhere = field
		datawhere.field = olddatawhere.field
		datawhere.order = olddatawhere.order
		tableIns.reload({
			where: datawhere,
			page: {curr: 1}
		});
	})
	</script>
</body>
</html>